<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<script type="text/javascript" src="<?php echo STATIC_DOMAIN;?>js/highcharts/js/highcharts.src.js"></script>
<script type="text/javascript">
    //Edit
    $(document).ready( function() 
    {
        $('#editStatus').editable('<?php echo site_url('bannerdetail/edit?bannerid='.$bannerdetailid.'&type=1')?>', 
        {  
            data   : "{'1':'<?php echo $bannerdetail_lang['run']?>','2':'<?php echo $bannerdetail_lang['paused']?>','3':'<?php echo $bannerdetail_lang['temp_delete']?>', 'selected':'<?php echo $info[0]['status']?>'}",
            type:"select",
            event : 'status_click',
            //cancel : 'Cancel',
            submit : 'OK',
            indicator : 'Wait...',
            id : 'hk',
            name : 'ns',
            css : 'inherit',
            cssclass : "editable",
            onblur    : "cancel",
            callback: function(value, settings) { 
                $('#edittriggerStatus').show();
            },
            "onreset": function() {
                $('#edittriggerStatus').show();
            }
        });
        $('#edittriggerStatus').bind('click', function() {
              $(this).prev().trigger('status_click');
              $('#edittriggerStatus').hide();
        });
        
        $('#editBanner').editable('<?php echo site_url('bannerdetail/edit?bannerid='.$bannerdetailid.'&type=0')?>', 
        {  
            event : 'banner_click',
            //cancel : 'Cancel',
            submit : 'OK',
            indicator : 'Wait...',
            id : 'hk',
            name : 'ns',
            css : 'inherit',
            cssclass : "editable",
            onblur    : "cancel",
            callback: function(value, settings) { 
                $('#edittriggerBanner').show();
            },
            "onreset": function() {
                $('#edittriggerBanner').show();
            }
        });
        $('#edittriggerBanner').bind('click', function() {
              $(this).prev().trigger('banner_click');
              $('#edittriggerBanner').hide();
        });
	});
</script>
        <!-- colum right -->
<div class="middle myclear">
	<div class="pad10">
		<div class="col-770">
			<!-- bread crumb -->
			<p id="bread-crumb">
				<a href="<?php echo site_url('campaign')?>">
					<?php echo $bannerdetail_lang['allCampaign']?>
				</a>
				
				<a href="<?php echo site_url('campaigndetail/index?campaignid='.$info[0]['campaignid'].'&fromdate='.$fromdate.'&todate='.$todate);?>">
					<?php echo $bannerdetail_lang['campaign']?>: <?php echo $info[0]['campaignname'];?>
				</a>
				
				<?php echo strip_tags($info[0]['bannername']);?>
			</p><!-- end bread crumb -->
			
			<table class="martop5 marbottom10" width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td class="mbdetail-title padbottom5">
						<span class="text-999"><?php echo $bannerdetail_lang['ad']?>: </span> <span class="text-666"><?php echo strip_tags($info[0]['bannername']);?></span>
					</td>
					<td class="ver-middle padbottom5">
						<p class="float-right">
							<a class="btn" href="/home/createad">
								<span><?php echo $bannerdetail_lang['creatAnAds']?></span>
							</a>
						</p>
					</td>
				</tr>
			</table>
				
			<div class="mbdetail-box myclear">
				<div class="mbdetail-info">
					<table  width="100%" cellpadding="0" cellspacing="0" border="0">
						<tr>
							<td >
								<div class="mbd-col-camp">
									<p class="text-999 padbottom5">
                                        <?php echo $bannerdetail_lang['campaignName']?>
									</p>
									<p>
										<?php echo $info[0]['campaignname'];?>
									</p>
								</div>
							</td>
							
							<td>
								<div class="mbd-col-banner">
									<p class="text-999 padbottom5">
										<?php echo $bannerdetail_lang['adName']?>
									</p>
									
									<p>
										<span id="editBanner"><?php echo strip_tags($info[0]['bannername']);?></span>
                                        <a id="edittriggerBanner" style="cursor:pointer" class="mbd-edit"><?php echo $bannerdetail_lang['edit']?></a>
									</p>
								</div>
							</td>
							
							<td>
								<div class="mbd-col-status">
									<p class="text-999 padbottom5">
										<?php echo $bannerdetail_lang['status']?>
									</p>
									<p>
                                        <span id="editStatus">
                                        <?php
                                        if($info[0]['outofstore']==1)
    										echo '<img src="/images/dealed.png" style="vertical-align: middle;"/><span class="ver-middle"> Đã hạ deal </span>';
                                        elseif($info[0]['status']==-1)
                                        	echo '<img src="/images/imgok.gif" style="vertical-align: middle;"/><span class="ver-middle"> Hoàn thành </span>';
                                        elseif($info[0]['status']==0) 
    										echo '<img src="/images/temp_deleted.gif" style="vertical-align: middle;"/><span class="ver-middle"> Xóa tạm </span>';
                                        elseif($info[0]['status']==1) 
    										echo '<img src="/images/imgrun.gif" style="vertical-align: middle;"/><span class="ver-middle"> Đang chạy </span>';
    									elseif($info[0]['status']==2)
    										echo '<img src="/images/imgpause.gif" style="vertical-align: middle;"/><span class="ver-middle"> Tạm dừng </span>';
                                        elseif($info[0]['status']==3)
    										echo '<img src="/images/imgwait.png" style="vertical-align: middle;"/><span class="ver-middle"> Chờ duyệt </span>';
                                        elseif($info[0]['status']==4)
    										echo '<img src="/images/imgproblem.png" style="vertical-align: middle;"/><span class="ver-middle"> Có lỗi </span>';
                                        elseif($info[0]['status']==5)
    										echo '<img src="/images/imgout-of-money.png" style="vertical-align: middle;"/><span class="ver-middle"> Hết ngân sách ngày </span>';
                                        elseif($info[0]['status']==6)
    										echo '<img src="/images/het_ngan_sach.gif" style="vertical-align: middle;"/><span class="ver-middle"> Hết ngân sách </span>';
                                        elseif($info[0]['status']==8)
    										echo '<img src="/images/chochay.gif" style="vertical-align: middle;"/><span class="ver-middle"> Chờ chạy </span>';
    									else
    										echo $info[0]['status'];
    									;?>
                                        </span>									
										<a id="edittriggerStatus" style="cursor:pointer;" class="mbd-edit ver-middle"><?php echo $bannerdetail_lang['edit']?></a>
									</p>
								</div>
							</td>
							
							<td>
								<div class="mbd-col-target">
									<p class="text-999">
										<?php echo $bannerdetail_lang['targeting']?>
									</p>
                                    <ul class="square">
                                        <li>
                                            <b><?php echo $bannerdetail_lang['locationAd']?> : </b> 
                                                <?php $mystring =$info[0]['locationAd'];
                                                if(strpos($mystring,'0')!==false) {
                                                     $mystring = str_replace("0","Toàn quốc",$mystring);
                                                }
                                                if(strpos($mystring,'1')!==false) {
                                                     $mystring = str_replace("1","Bắc",$mystring);
                                                }
                                                if(strpos($mystring,'2')!==false) {
                                                     $mystring = str_replace("2","Trung",$mystring);
                                                }
                                                if(strpos($mystring,'3')!==false) {
                                                     $mystring = str_replace("3","Nam",$mystring);
                                                }
                                                echo rtrim($mystring,',');
                                                 ?>
                                        </li>
                                        <?php if(count($category)!=0)
                                        {
                                        ?>
                                        <li>
                                            <b><?php echo $bannerdetail_lang['likeAndInterest']?> : </b>
                                            <?php $indexCat=0;
                                            foreach($category as $ctgr)
                                            {
                                                if($indexCat==3)
                                                {
                                                    break;
                                                }
                                            ?>
    											<p>
    												<?php echo $ctgr['categoryname_vi'];?>
    											</p>
                                            <?php
                                                $indexCat++;
                                            }
                                            ?>
                                        </li>
                                        <?php
                                        }
                                        ?>
                                    </ul>
									
								</div>
							</td>
						</tr>
					</table>
					
									
				</div> <!-- end .mbdetail-info -->
				
				<table class="mbd-timebox" cellpadding="0" cellspacing="0" border="0">	
					<tr>
						<td class="padright5 ver-middle">
							<input class="input-time" type="text" id="date" value="<?php echo date('d/m/Y',strtotime($fromdate))?> <?php echo $bannerdetail_lang['to']?> <?php echo date('d/m/Y',strtotime($todate));?>" />
						</td>
                        <td class="ver-middle">
                            <img id="loading1" src="/images/ajaxLoading.gif" class="martop5 ver-middle" style="display: none;"/>
                        </td>
					</tr>
				</table>	
				<div id="campaigndiv">
				<!-- thong ke -->
				<div class="myclear">
					<!-- mbd-440 -->
					<div class="mbd-440 marright10">						
						<table class="tbl-list DataTable" width="100%" cellpadding="0" cellspacing="0" border="1" id="table">
                        <thead>
							<tr>
								<th class="td-label">
									<b><?php echo $bannerdetail_lang['date']?></b>
								</th>
								
								<th class="td-label text-right">
									<b>Click</b>
								</th>
								
								<th class="td-label text-right">
									<b>Impression</b>
								</th>
								
								<th class="td-label text-right">
									<b>Unique Visitor</b>
								</th>
								
								<th class="td-label text-right">
									<b>CTR %</b>
								</th>
								
								<th class="td-label text-right">
									<b><?php echo $bannerdetail_lang['spent']?></b>(VND)
								</th>
							</tr>
                        </thead>
                        <tbody>
                            <?php $index=1;
                                $spent=0;
                            foreach($bannerdetail as $bn)
                            { 
                                $bgcolor = ($index%2==0)?'class="bg-color-gray"':'';
                            ?>
							<tr <?php echo $bgcolor?>>
								<td>
									<p class="mbd-sta-date">
										<?php echo $bn['clickdate'];?>
									</p>
								</td>
								<td>
									<p class="mbd-sta-click">
										<?php echo number_format($bn['clicks']);?>
									</p>
								</td>
								<td>
									<p class="mbd-sta-imp">
										<?php echo number_format($bn['impressions']);?>
									</p>
								</td>
								<td>
									<p class="mbd-sta-uvisitor">
										<?php echo number_format($bn['uviews']);?>
									</p>
								</td>
								<td>
									<p class="mbd-sta-ctr">
										<?php echo $bn['CTR'];?>
									</p>
								</td>
								<td>
									<p class="mbd-sta-money">
										<?php echo number_format($bn['money']);?>
									</p>
								</td>
							</tr>
							<?php
                            $index++;
                            }
                            ?>
                        </tbody>
                        <tr>
                            <td>
                                <p class="mbd-sta-date">
                                    <b><?php echo $bannerdetail_lang['total'];?></b>
                                </p>
                            </td>
                            <td>
    							<p class="mbd-sta-click">
    								<b><?php echo number_format($total[0]['clicks']);?></b>
    							</p>
    						</td>
                            <td>
								<p class="mbd-sta-imp">
									<b><?php echo number_format($total[0]['views']);?></b>
								</p>
							</td>
                            <td>
								<p class="mbd-sta-uvisitor">
									<b><?php echo number_format($total[0]['uviews']);?></b>
								</p>
							</td>
                            <td>
								<p class="mbd-sta-ctr">
									<b><?php echo $total[0]['CTR'];?></b>
								</p>
							</td>
							<td>
								<p class="mbd-sta-money">
									<b><?php echo number_format($total[0]['money']);?></b>
								</p>
							</td>
                        </tr>
						</table>
						<div id="pager" style="font-family: tahoma;border: solid 1px #D6D6D6;width: 165px;float: right; margin-top: 10px;background-color: white;padding:3px 10px 3px 10px">
                        	<form>
                                <span style="vertical-align: middle;"><?php echo $bannerdetail_lang['page'];?></span>
                                <input type="text" class="pagedisplay" size="2" style="border:0;vertical-align: middle;"/>
                        		<img src="/images/imgpre.gif" class="prev" id="prev" style="vertical-align: middle;"/>
                        		<img src="/images/imgnext.gif" class="next" id="next" style="vertical-align: middle;"/>
                        		<select class="pagesize" style="vertical-align: middle;border: 0 none;background: #fff;">
                        			<option selected="selected" value="10">10</option>
                        			<option value="20">20</option>
                        			<option value="30">30</option>
                        			<option  value="40">40</option>
                        		</select>
                        	</form>
                        </div>
					</div> <!-- end .mbd-440 -->
					
					<!-- mbd-300 -->
					<div class="mbd-300">	
						
						<div class="mbd-breview">
							<p class="bold">
								<?php echo $info[0]['bannername'];?>
							</p>
							
							<p class="breview-box-domain">
								<?php echo $this->mycommon->getDomainFromUrl($info[0]['url']);?>
							</p>
							
							<div class="myclear padtop5">
								<p class="breview-box-img">
                                    <a href="<?php echo $info[0]['url'];?>" target="_blank">
									   <img alt="" src="<?php echo $info[0]['filepath'];?>" />
                                    </a>
								</p>
								<div class="breview-box-bodytext">
									<?php echo $info[0]['description'];?>
								</div>
								<!-- important. fix for ie 6. Don't remove -->
								<!--[if IE 6]><br class="clearboth" /><![endif]-->
							</div>
						</div>
						
						<div class="martop10 myclear">
							<a class="graybtn">
								<span><?php echo $bannerdetail_lang['search']?></span>
							</a>
                            <a href="<?php echo site_url('../home/editAd/'.$bannerdetailid);?>" class="graybtn marleft20">
								<span><?php echo $bannerdetail_lang['editBanner']?></span>
							</a>
						</div>
						
					</div> <!-- end .mbd-300 -->
					
					<!-- important. fix for ie 6. Don't remove -->
					<!--[if IE 6]><br class="clearboth" /><![endif]-->
				</div>
				<!-- end thong ke -->
			
				<div class="mbd-chartbox myclear">
					<div class="myclear marleft20">
						<a class="graybtn marright5">
							<span class="curr" onclick="ajax_chart(0);" id="clicks">Clicks</span>
						</a>
						
						<a class="graybtn">
							<span onclick="ajax_chart(1);" id="impressions">Impressions</span>
						</a>
                        <a class="marleft10">
							<img id="loading" src="/images/ajaxLoading.gif" class="martop5 ver-middle" style="display: none;"/>
						</a>
					</div>			
                    <div id="my_chart"></div>
				</div>
			</div>
			</div><!-- end .mbdetail-box -->
			
			<br /><br /><br /><br /><br />
			
			<p class="text-right pad10">
				<img id="top" class="cursor-pointer" alt="" src="/images/backtotop.gif" onclick="window.scrollTo(0,0); return false;"/>
			</p>
		</div> <!-- end colum right -->
    </div> <!-- end page content -->
</div>
<script type="text/javascript">
    function ajax_chart(val)
    {
        var temp =$('#date').val();
        var arrTime = temp.toString().split(' <?php echo $bannerdetail_lang['to']?> ');
        var fromdate = arrTime[0];
        var todate = arrTime[1];
        var strReplace="/";
        fromdate=fromdate.replace(/\//g,'-');
        todate=todate.replace(/\//g,'-');
        var onSuccess= function(data) 
        {
            if(val==0)
            {
                $('#impressions').removeClass("curr");
                $('#clicks').addClass("curr");
            }else{
                $('#clicks').removeClass("curr");
                $('#impressions').addClass("curr");
            }
            $('#my_chart').html(data);
            $('#loading').hide();
        };
        $('#loading').show();
        var strURL="<?php echo site_url('bannerdetail/click_chart?bannerid='.$bannerdetailid.'&fromdate=');?>"+fromdate+"&todate="+todate+"&type="+val;
        getAjax(strURL,"",'', '', '', false, onSuccess);
    }
    
    $(document).ready( function() 
    {
        <?php if(count($bannerdetail) >0 )
        {
        ?>
        jQuery.tablesorter.addParser({
          id: "fancyNumber",
          is: function(s) {
            return false;
          },
          format: function(s) {
            return parseFloat( s.replace(/,/g,'') );
          },
          type: "numeric"
        });
       	$('#table').tablesorter({headers: 
        { 
            1: {sorter:'fancyNumber'},
            2: {sorter:'fancyNumber'},
            3: {sorter:'fancyNumber'},
            5: {sorter:'fancyNumber'}
        }
        }).tablesorterPager({container: $("#pager")});
        <?php
        }
        ?>
    });
    
    $('#date').DatePicker({
        format: 'd/m/Y',
        date: ['<?php echo date('d/m/Y',strtotime($fromdate));?>','<?php echo date('d/m/Y',strtotime($todate));?>'],
        current: '<?php echo date('d/m/Y');?>',
        calendars: 2,
        mode: 'range',
        starts: 1, 
        onChange: function(formated, dates) 
        {
            $('#loading1').show();
            $('#date').val(formated.join(' <?php echo $bannerdetail_lang['to']?> '));
            $('#date').DatePickerHide();
            var arrTime = formated.toString().split(',');
            var fromdate = arrTime[0];
            var todate = arrTime[1];
            var strReplace="/";
            fromdate=fromdate.replace(/\//g,'-');
            todate=todate.replace(/\//g,'-');
            var type = ($('#clicks').attr('class')=='curr') ? 0:1;
            var strURL="<?php echo site_url('bannerdetail/timeFilter/?bannerid='.$bannerdetailid);?>&fromdate="+fromdate+"&todate="+todate+"&type="+type;
            var success = function(data)
            {
            	$('#campaigndiv').html(data);
            	$('#loading1').hide();
            };
    	   getAjax(strURL,"",'', '', '', false, success);
        }
    });
    ajax_chart(0);
</script>